package com.xyy.saas.payment.merchant.core.dto;

import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

@Data
@Builder
public class RegisterCancelDto {
    /**
     * 业务线
     */
    private String businessIdType;
    /**
     * 支付平台商户标识
     */
    private String accountId;
    /**
     * 原业务单号，支付平台支付单号
     */
    private String origBusinessOrderNo;
    /**
     * 原订单号
     */
    private String origOrderNo;
    /**
     * 挂账金额
     */
    private Integer amount;
    /**
     * 平台收取手续费
     */
    private Integer fee;
    /**
     * 备注
     */
    private String remark;

    /**
     * 重写get方法
     */
    public Integer getFee() {
        return fee == null ? NumberUtils.INTEGER_ZERO : fee;
    }

    /**
     * 参数校验
     */
    public void checkParam() throws PaymentException {
        if(StringUtils.isBlank(businessIdType)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "业务线不能为空");
        }

        if(StringUtils.isBlank(accountId)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "商户标识不能为空");
        }

        if(StringUtils.isBlank(origBusinessOrderNo)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "业务单号不能为空");
        }

        if(amount == null || amount <= NumberUtils.INTEGER_ZERO) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "关账金额必须大于0");
        }
    }
}
